package Servlet;

import DAO.MessageDAO;
import pojo.UserMessage;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Objects;
@WebServlet(name= "writeArticleServlet",value = "/writeArticleServlet")
public class WriteArticleServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        int userID= Integer.parseInt(request.getParameter("userID"));
        String articleTitle = request.getParameter("articleTitle");
        String articleContent  = request.getParameter("articleContent");
        MessageDAO messageDAO  = new MessageDAO();
        if(articleContent!="" && articleTitle!=""){

            if(messageDAO.writeArticleS(userID,articleTitle,articleContent)==true){
                response.getWriter().write("success");
            }
            else {
                response.getWriter().print("failed");
            }
        }
        else {
            response.getWriter().write("内容或标题不能为空！");
        }
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
}
